home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drivers / batman.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  12KB  |  388 lines

  1. /***************************************************************************
  2.  
  3.     Batman
  4.  
  5.     driver by Aaron Giles
  6.  
  7. ****************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "machine/atarigen.h"
  11. #include "sndhrdw/atarijsa.h"
  12. #include "vidhrdw/generic.h"
  13.  
  14.  
  15. void batman_set_alpha_bank(int bank);
  16. WRITE_HANDLER( batman_playfieldram_w );
  17. WRITE_HANDLER( batman_playfield2ram_w );
  18. WRITE_HANDLER( batman_colorram_w );
  19.  
  20. int batman_vh_start(void);
  21. void batman_vh_stop(void);
  22. void batman_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  23.  
  24. void batman_scanline_update(int scanline);
  25.  
  26.  
  27. static UINT8 *latch_data;
  28.  
  29.  
  30. /*************************************
  31.  *
  32.  *    Initialization
  33.  *
  34.  *************************************/
  35.  
  36. static void update_interrupts(void)
  37. {
  38.     int newstate = 0;
  39.  
  40.     if (atarigen_scanline_int_state)
  41.         newstate |= 4;
  42.     if (atarigen_sound_int_state)
  43.         newstate |= 6;
  44.  
  45.     if (newstate)
  46.         cpu_set_irq_line(0, newstate, ASSERT_LINE);
  47.     else
  48.         cpu_set_irq_line(0, 7, CLEAR_LINE);
  49. }
  50.  
  51.  
  52. static void init_machine(void)
  53. {
  54.     atarigen_eeprom_reset();
  55.     atarigen_video_control_reset();
  56.     atarigen_interrupt_reset(update_interrupts);
  57.     atarigen_scanline_timer_reset(batman_scanline_update, 8);
  58.     atarijsa_reset();
  59. }
  60.  
  61.  
  62.  
  63. /*************************************
  64.  *
  65.  *    I/O handling
  66.  *
  67.  *************************************/
  68.  
  69. static READ_HANDLER( special_port2_r )
  70. {
  71.     int result = input_port_2_r(offset);
  72.  
  73.     if (atarigen_sound_to_cpu_ready) result ^= 0x0010;
  74.     if (atarigen_cpu_to_sound_ready) result ^= 0x0020;
  75.  
  76.     return result;
  77. }
  78.  
  79.  
  80. static WRITE_HANDLER( latch_w )
  81. {
  82.     int oldword = READ_WORD(latch_data);
  83.     int newword = COMBINE_WORD(oldword, data);
  84.     WRITE_WORD(latch_data, newword);
  85.  
  86.     /* bit 4 is connected to the /RESET pin on the 6502 */
  87.     if (newword & 0x0010)
  88.         cpu_set_reset_line(1, CLEAR_LINE);
  89.     else
  90.         cpu_set_reset_line(1, ASSERT_LINE);
  91.  
  92.     /* alpha bank is selected by the upper 4 bits */
  93.     if ((oldword ^ newword) & 0x7000)
  94.         batman_set_alpha_bank((newword >> 12) & 7);
  95. }
  96.  
  97.  
  98.  
  99. /*************************************
  100.  *
  101.  *    Main CPU memory handlers
  102.  *
  103.  *************************************/
  104.  
  105. static struct MemoryReadAddress main_readmem[] =
  106. {
  107.     { 0x000000, 0x0bffff, MRA_ROM },
  108.     { 0x100000, 0x10ffff, MRA_BANK1 },
  109.     { 0x120000, 0x120fff, atarigen_eeprom_r },
  110.     { 0x3e0000, 0x3e0fff, paletteram_word_r },
  111.     { 0x3effc0, 0x3effff, atarigen_video_control_r },
  112.     { 0x260000, 0x260001, input_port_0_r },
  113.     { 0x260002, 0x260003, input_port_1_r },
  114.     { 0x260010, 0x260011, special_port2_r },
  115.     { 0x260030, 0x260031, atarigen_sound_r },
  116.     { 0x3f0000, 0x3f5fff, MRA_BANK3 },
  117.     { 0x3f6000, 0x3f7fff, MRA_BANK4 },
  118.     { 0x3f8000, 0x3f8fff, MRA_BANK5 },
  119.     { 0x3f9000, 0x3fffff, MRA_BANK6 },
  120.     { -1 }  /* end of table */
  121. };
  122.  
  123.  
  124. static struct MemoryWriteAddress main_writemem[] =
  125. {
  126.     { 0x000000, 0x0bffff, MWA_ROM },
  127.     { 0x100000, 0x10ffff, MWA_BANK1 },
  128.     { 0x120000, 0x120fff, atarigen_eeprom_w, &atarigen_eeprom, &atarigen_eeprom_size },
  129.     { 0x260040, 0x260041, atarigen_sound_w },
  130.     { 0x260050, 0x260051, latch_w, &latch_data },
  131.     { 0x260060, 0x260061, atarigen_eeprom_enable_w },
  132.     { 0x2a0000, 0x2a0001, watchdog_reset_w },
  133.     { 0x3e0000, 0x3e0fff, atarigen_666_paletteram_w, &paletteram },
  134.     { 0x3effc0, 0x3effff, atarigen_video_control_w, &atarigen_video_control_data },
  135.     { 0x3f0000, 0x3f1fff, batman_playfield2ram_w, &atarigen_playfield2ram, &atarigen_playfield2ram_size },
  136.     { 0x3f2000, 0x3f3fff, batman_playfieldram_w, &atarigen_playfieldram, &atarigen_playfieldram_size },
  137.     { 0x3f4000, 0x3f5fff, batman_colorram_w, &atarigen_playfieldram_color },
  138.     { 0x3f6000, 0x3f7fff, MWA_BANK4, &atarigen_spriteram, &atarigen_spriteram_size },
  139.     { 0x3f8000, 0x3f8fff, MWA_BANK5, &atarigen_alpharam, &atarigen_alpharam_size },
  140.     { 0x3f9000, 0x3fffff, MWA_BANK6 },
  141.     { -1 }  /* end of table */
  142. };
  143.  
  144.  
  145.  
  146. /*************************************
  147.  *
  148.  *    Port definitions
  149.  *
  150.  *************************************/
  151.  
  152. INPUT_PORTS_START( batman )
  153.     PORT_START        /* 26000 */
  154.     PORT_BIT( 0x01ff, IP_ACTIVE_LOW, IPT_UNUSED )
  155.     PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_START1 )
  156.     PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER1 )
  157.     PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER1 )
  158.     PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_UNUSED )
  159.     PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_PLAYER1 )
  160.     PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT | IPF_PLAYER1 )
  161.     PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN | IPF_PLAYER1 )
  162.     PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_JOYSTICK_UP | IPF_PLAYER1 )
  163.  
  164.     PORT_START        /* 26002 */
  165.     PORT_BIT( 0xffff, IP_ACTIVE_LOW, IPT_UNUSED )
  166.  
  167.     PORT_START        /* 26010 */
  168.     PORT_BIT( 0x000f, IP_ACTIVE_LOW, IPT_UNUSED )
  169.     PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_UNUSED )    /* Input buffer full (@260030) */
  170.     PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_UNUSED )    /* Output buffer full (@260040) */
  171.     PORT_SERVICE( 0x0040, IP_ACTIVE_LOW )
  172.     PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_VBLANK )
  173.  
  174.     JSA_III_PORT    /* audio board port */
  175. INPUT_PORTS_END
  176.  
  177.  
  178.  
  179. /*************************************
  180.  *
  181.  *    Graphics definitions
  182.  *
  183.  *************************************/
  184.  
  185. static struct GfxLayout anlayout =
  186. {
  187.     8,8,    /* 8*8 chars */
  188.     8192,    /* 8192 chars */
  189.     2,        /* 2 bits per pixel */
  190.     { 0, 4 },
  191.     { 0, 1, 2, 3, 8, 9, 10, 11 },
  192.     { 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16 },
  193.     8*16    /* every char takes 16 consecutive bytes */
  194. };
  195.  
  196.  
  197. static struct GfxLayout pfmolayout =
  198. {
  199.     8,8,    /* 8*8 sprites */
  200.     32768,    /* 32768 of them */
  201.     4,        /* 4 bits per pixel */
  202.     { 0*8*0x80000, 1*8*0x80000, 2*8*0x80000, 3*8*0x80000 },
  203.     { 0, 1, 2, 3, 4, 5, 6, 7 },
  204.     { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
  205.     8*8    /* every sprite takes 8 consecutive bytes */
  206. };
  207.  
  208.  
  209. static struct GfxDecodeInfo gfxdecodeinfo[] =
  210. {
  211.     { REGION_GFX2, 0x040000, &pfmolayout,  512, 64 },        /* sprites & playfield */
  212.     { REGION_GFX2, 0x000000, &pfmolayout,  256, 64 },        /* sprites & playfield */
  213.     { REGION_GFX1, 0x000000, &anlayout,      0, 64 },        /* characters 8x8 */
  214.     { -1 } /* end of array */
  215. };
  216.  
  217.  
  218.  
  219. /*************************************
  220.  *
  221.  *    Machine driver
  222.  *
  223.  *************************************/
  224.  
  225. static struct MachineDriver machine_driver_batman =
  226. {
  227.     /* basic machine hardware */
  228.     {
  229.         {
  230.             CPU_M68000,
  231.             ATARI_CLOCK_14MHz,
  232.             main_readmem,main_writemem,0,0,
  233.             ignore_interrupt,1
  234.         },
  235.         JSA_III_CPU
  236.     },
  237.     60, DEFAULT_REAL_60HZ_VBLANK_DURATION,    /* frames per second, vblank duration */
  238.     1,
  239.     init_machine,
  240.  
  241.     /* video hardware */
  242.     42*8, 30*8, { 0*8, 42*8-1, 0*8, 30*8-1 },
  243.     gfxdecodeinfo,
  244.     2048, 2048,
  245.     0,
  246.  
  247.     VIDEO_TYPE_RASTER | VIDEO_MODIFIES_PALETTE | VIDEO_UPDATE_BEFORE_VBLANK,
  248.     0,
  249.     batman_vh_start,
  250.     batman_vh_stop,
  251.     batman_vh_screenrefresh,
  252.  
  253.     /* sound hardware */
  254.     JSA_III_MONO(REGION_SOUND1),
  255.  
  256.     atarigen_nvram_handler
  257. };
  258.  
  259.  
  260.  
  261. /*************************************
  262.  *
  263.  *    ROM decoding
  264.  *
  265.  *************************************/
  266.  
  267. static void rom_decode(void)
  268. {
  269.     UINT8 *base = memory_region(REGION_SOUND1);
  270.     int i;
  271.  
  272.     /* invert the graphics bits on the playfield and motion objects */
  273.     for (i = 0; i < memory_region_length(REGION_GFX2); i++)
  274.         memory_region(REGION_GFX2)[i] ^= 0xff;
  275.  
  276.     /* expand the ADPCM data to avoid lots of memcpy's during gameplay */
  277.     /* the upper 128k is fixed, the lower 128k is bankswitched */
  278.     memcpy(&base[0x00000], &base[0x80000], 0x20000);
  279.     memcpy(&base[0x40000], &base[0x80000], 0x20000);
  280.     memcpy(&base[0x80000], &base[0xa0000], 0x20000);
  281.     memcpy(&base[0xc0000], &base[0xc0000], 0x20000);
  282.  
  283.     memcpy(&base[0x20000], &base[0xe0000], 0x20000);
  284.     memcpy(&base[0x60000], &base[0xe0000], 0x20000);
  285.     memcpy(&base[0xa0000], &base[0xe0000], 0x20000);
  286.     memcpy(&base[0xe0000], &base[0xe0000], 0x20000);
  287. }
  288.  
  289.  
  290.  
  291. /*************************************
  292.  *
  293.  *    Driver initialization
  294.  *
  295.  *************************************/
  296.  
  297. static void init_batman(void)
  298. {
  299.     static const UINT16 default_eeprom[] =
  300.     {
  301.         0x0001,0x01F1,0x0154,0x01C5,0x0100,0x0113,0x0300,0x0173,
  302.         0x0700,0x0154,0x0200,0x0107,0x0100,0x0120,0x0300,0x0165,
  303.         0x0125,0x0100,0x0149,0x019D,0x016C,0x018B,0x01F1,0x0154,
  304.         0x01C5,0x0100,0x0113,0x0300,0x0173,0x0700,0x0154,0x0200,
  305.         0x0107,0x0100,0x0120,0x0300,0x0165,0x0125,0x0100,0x0149,
  306.         0x019D,0x016C,0x018B,0x6800,0x0134,0x0113,0x0148,0x0100,
  307.         0x019A,0x0105,0x01DC,0x01A2,0x013A,0x0139,0x0100,0x0105,
  308.         0x01AB,0x016A,0x0149,0x0100,0x01ED,0x0105,0x0185,0x01B2,
  309.         0x0134,0x0100,0x0105,0x0160,0x01AA,0x0149,0x0100,0x0105,
  310.         0x012A,0x0152,0x0110,0x0100,0x0168,0x0105,0x0113,0x012E,
  311.         0x0150,0x0218,0x01D0,0x0100,0x01D0,0x0300,0x01D0,0x0600,
  312.         0x01D0,0x02C8,0x0000
  313.     };
  314.  
  315.     atarigen_eeprom_default = default_eeprom;
  316.     atarijsa_init(1, 3, 2, 0x0040);
  317.  
  318.     /* speed up the 6502 */
  319.     atarigen_init_6502_speedup(1, 0x4163, 0x417b);
  320.  
  321.     /* display messages */
  322.     atarigen_show_sound_message();
  323.  
  324.     rom_decode();
  325. }
  326.  
  327.  
  328.  
  329. /*************************************
  330.  *
  331.  *    ROM definition(s)
  332.  *
  333.  *************************************/
  334.  
  335. ROM_START( batman )
  336.     ROM_REGION( 0xc0000, REGION_CPU1 )    /* 6*128k for 68000 code */
  337.     ROM_LOAD_EVEN( "085-2030.10r",  0x00000, 0x20000, 0x7cf4e5bf )
  338.     ROM_LOAD_ODD ( "085-2031.7r",   0x00000, 0x20000, 0x7d7f3fc4 )
  339.     ROM_LOAD_EVEN( "085-2032.91r",  0x40000, 0x20000, 0xd80afb20 )
  340.     ROM_LOAD_ODD ( "085-2033.6r",   0x40000, 0x20000, 0x97efa2b8 )
  341.     ROM_LOAD_EVEN( "085-2034.9r",   0x80000, 0x20000, 0x05388c62 )
  342.     ROM_LOAD_ODD ( "085-2035.5r",   0x80000, 0x20000, 0xe77c92dd )
  343.  
  344.     ROM_REGION( 0x14000, REGION_CPU2 )    /* 64k + 16k for 6502 code */
  345.     ROM_LOAD( "085-1040.12c",  0x10000, 0x4000, 0x080db83c )
  346.     ROM_CONTINUE(              0x04000, 0xc000 )
  347.  
  348.     ROM_REGION( 0x20000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  349.     ROM_LOAD( "085-2009.10m",  0x00000, 0x20000, 0xa82d4923 )    /* alphanumerics */
  350.  
  351.     ROM_REGION( 0x200000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  352.     ROM_LOAD( "085-1010.13r",  0x000000, 0x20000, 0x466e1365 )    /* graphics, plane 0 */
  353.     ROM_LOAD( "085-1014.14r",  0x020000, 0x20000, 0xef53475a )
  354.     ROM_LOAD( "085-1018.15r",  0x040000, 0x20000, 0x4c14f1e5 )
  355.     ROM_LOAD( "085-1022.16r",  0x060000, 0x20000, 0x7476a15d )
  356.  
  357.     ROM_LOAD( "085-1011.13m",  0x080000, 0x20000, 0x8cda5efc )    /* graphics, plane 1 */
  358.     ROM_LOAD( "085-1015.14m",  0x0a0000, 0x20000, 0x043e7f8b )
  359.     ROM_LOAD( "085-1019.15m",  0x0c0000, 0x20000, 0x2046d9ec )
  360.     ROM_LOAD( "085-1023.16m",  0x0e0000, 0x20000, 0x75cac686 )
  361.  
  362.     ROM_LOAD( "085-1012.13f",  0x100000, 0x20000, 0xb017f2c3 )    /* graphics, plane 2 */
  363.     ROM_LOAD( "085-1016.14f",  0x120000, 0x20000, 0x70aa2360 )
  364.     ROM_LOAD( "085-1020.15f",  0x140000, 0x20000, 0xcc4f4b94 )
  365.     ROM_LOAD( "085-1024.16f",  0x160000, 0x20000, 0xd60d35e0 )
  366.  
  367.     ROM_LOAD( "085-1013.13c",  0x180000, 0x20000, 0x68b64975 )    /* graphics, plane 3 */
  368.     ROM_LOAD( "085-1017.14c",  0x1a0000, 0x20000, 0xe4af157b )
  369.     ROM_LOAD( "085-1021.15c",  0x1c0000, 0x20000, 0x9c8ef9ba )
  370.     ROM_LOAD( "085-1025.16c",  0x1e0000, 0x20000, 0x5d30bcd1 )
  371.  
  372.     ROM_REGION( 0x100000, REGION_SOUND1 )    /* 1MB for ADPCM */
  373.     ROM_LOAD( "085-1041.19e",  0x80000, 0x20000, 0xd97d5dbb )
  374.     ROM_LOAD( "085-1042.17e",  0xa0000, 0x20000, 0x8c496986 )
  375.     ROM_LOAD( "085-1043.15e",  0xc0000, 0x20000, 0x51812d3b )
  376.     ROM_LOAD( "085-1044.12e",  0xe0000, 0x20000, 0x5e2d7f31 )
  377. ROM_END
  378.  
  379.  
  380.  
  381. /*************************************
  382.  *
  383.  *    Game driver(s)
  384.  *
  385.  *************************************/
  386.  
  387. GAME( 1991, batman, 0, batman, batman, batman, ROT0, "Atari Games", "Batman" )
  388.